/**
 * Copyright (c) 2017-present, Liu Jinyong
 * All rights reserved.
 *
 * https://github.com/huanxsd/MeiTuan
 * @flow
 */

import { Dimensions, Platform, PixelRatio } from 'react-native'

// 58 app 只有竖屏模式，所以可以只获取一次 width
const deviceWidthDp = Dimensions.get('window').width
// UI 默认给图是 640
const uiWidthPx = 720

function pxToDpFunc(uiElementPx) {
  return uiElementPx * deviceWidthDp / uiWidthPx
}

export default {
  width: Dimensions.get('window').width,
  height: Dimensions.get('window').height,
  onePixel: 1 / PixelRatio.get(),
  statusBarHeight: Platform.OS === 'ios' ? 20 : 0,
  pxToDp: pxToDpFunc,
}
